console.log('hmo.js')
//
// const request = new XMLHttpRequest();
// request.open('get','http://qq.com:8888/friends.json');
// request.onreadystatechange = ()=>{
//     if (request.readyState===4 && request.status===200){
//         const object = JSON.parse(request.response)
//         console.log(object);
//     }
// }
// request.send()

function jsonp(url) {
    return new Promise((resolve,reject)=>{
        const random = 'hmoJSONPCallbackName'+Math.random();
        window[random] = (data) =>{
            console.log(data)
            resolve(data);
        }
        const script = document.createElement('script');
        script.src = `${url}?callback=${random}`;
        script.onload = ()=>{
            script.remove();
        }
        script.onerror = ()=>{
            reject();
        }
        document.body.appendChild(script)
    })
}

jsonp("http://qq.com:8888/friends.js").then((data)=>{
    console.log(data);
})